package com.engineering.elink.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.engineering.elink.co.BaseCo;
import com.engineering.elink.co.HierCo;
import com.engineering.elink.common.ErrorType;
import com.engineering.elink.service.PlannHierService;
import com.engineering.elink.util.ResJsonUtil;

@RestController
@CrossOrigin
@RequestMapping("/api/plannhier")
@Api(value="规划体系接口")
public class PlannHierController {

	@Autowired
	private PlannHierService plannHierService;
	
	/**
	 * 规划体系列表
	 */
	@RequestMapping(value="/getList",method = RequestMethod.GET)
	@ApiOperation(value = "规划体系列表")
	public Map<String, Object> getList(@ModelAttribute @Valid BaseCo co){
		return ResJsonUtil.getMap(ErrorType.SUCCESS, plannHierService.getPlannHiersList(co));
	}
	
	/**
	 * 规划体系单个详情
	 */
	@RequestMapping(value="/get",method = RequestMethod.GET)
	@ApiOperation(value = "规划体系单个详情")
	public Map<String, Object> get(
			@ApiParam(value="体系id",required=true) @RequestParam(value = "hierId",required=true)Integer hierId,HttpServletRequest request){
		@SuppressWarnings("unchecked")
		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
		String userId=null;
		if(userInfo!=null && userInfo.get("userId")!=null){
			userId =  userInfo.get("userId").toString();
		}
		
		return plannHierService.get(hierId,userId);
	}
	
	/**
	 * 获取工程技能
	 */
	@RequestMapping(value="/getSkill",method = RequestMethod.GET)
	@ApiOperation(value = "获取工程技能")
	public Map<String, Object> getSkill(@ModelAttribute @Valid HierCo co){
//		@SuppressWarnings("unchecked")
//		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
//		String userId =  userInfo.get("userId").toString();
		
		return plannHierService.getSkill(co,"");
	}
	
	/**
	 * 获取工程视频
	 */
	@RequestMapping(value="/getCourse",method = RequestMethod.GET)
	@ApiOperation(value = "获取工程视频")
	public Map<String, Object> getCourse(@ModelAttribute @Valid HierCo co){
//		@SuppressWarnings("unchecked")
//		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
//		String userId =  userInfo.get("userId").toString();
		
		return plannHierService.getCourse(co,"");
	}
	
	/**
	 * 获取工程资料
	 */
	@RequestMapping(value="/getFile",method = RequestMethod.GET)
	@ApiOperation(value = "获取工程资料")
	public Map<String, Object> getFile(@ModelAttribute @Valid HierCo co){
//		@SuppressWarnings("unchecked")
//		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
//		String userId =  userInfo.get("userId").toString();
		
		return plannHierService.getFile(co,"");
	}
	
	//@ApiParam(value="显示条数,默认为10条",defaultValue="10") @RequestParam("count") @DefaultValue("10") int count
	@RequestMapping(value="/getCareerPlann",method = RequestMethod.GET)
	@ApiOperation(value = "职业类目(支持分页)")
	public Map<String, Object> getCareerPlann(@ModelAttribute @Valid BaseCo co){
		
		return plannHierService.getCareerPlann(co);
	}
	
}
